#region License

// This file is part of Grawlix.
// 
// Grawlix is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as
// published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
// Grawlix is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public
// License along with Grawlix.  If not, see
// <http://www.gnu.org/licenses/>.

#endregion

using System;
using System.Collections.Generic;
using System.Drawing;
using Grawlix.Concurrency;
using Grawlix.Geometry;
using Grawlix.Services.Resources;

namespace Grawlix.Services.Rendering
{
	/// <summary>
	/// An object that renders to the screen.
	/// </summary>
	public interface IRenderDevice
	{
		/// <summary>
		/// Gets the thread affinity checker.
		/// </summary>
		/// <value>The object used to assert that operations happen on
		/// a particular thread.</value>
		ThreadAffinity Affinity { get; }

		/// <summary>
		/// Clears the screen.
		/// </summary>
		void Clear();

		/// <summary>
		/// Clips the screen to the specified area.
		/// </summary>
		/// <param name="area">The area to clip to.</param>
		/// <returns>A object that reverses the clipping on disposal.
		/// </returns>
		/// <remarks>Call this within a using statement.</remarks>
		IDisposable Clip(Rect area);

		/// <summary>
		/// Draws a flat-shaded rectangle on the screen.
		/// </summary>
		/// <param name="color">The color of the rectangle.</param>
		/// <param name="target">The target area to draw.</param>
		void DrawRectangle(Color color, Rect target);

		/// <summary>
		/// Draws a series of already-laid-out text.
		/// </summary>
		/// <param name="runs">The series of text runs to draw.</param>
		/// <param name="origin">The origin with respect to the laid
		/// out text.</param>
		/// <exception cref="ArgumentNullException"><c>runs</c> is
		/// null.</exception>
		void DrawText(IEnumerable<TextRun> runs, Vector2 origin);

		/// <summary>
		/// Draws a piece of specified texture on the screen.
		/// </summary>
		/// <param name="texture">The texture to draw.</param>
		/// <param name="source">The area within the texture to use.
		/// </param>
		/// <param name="tint">The color to tint the texture.</param>
		/// <param name="target">Where to draw the rect on the screen.
		/// </param>
		/// <exception cref="ArgumentNullException"><c>texture</c> is
		/// null.</exception>
		/// <exception cref="ArgumentException">Incompatible texture
		/// state.</exception>
		void DrawTexture(ITextureState texture, Rect source,
		                 Color tint, Rect target);

		/// <summary>
		/// Finishes the active render.
		/// </summary>
		void Finish();

		/// <summary>
		/// Loads the specified font into the renderer.
		/// </summary>
		/// <param name="font">The font to load.</param>
		/// <returns>The renderer font state.</returns>
		/// <exception cref="ArgumentNullException"><c>font</c> is
		/// null.</exception>
		IFontState LoadFont(Font font);

		/// <summary>
		/// Loads a texture into the renderer.
		/// </summary>
		/// <param name="image">The image to load.</param>
		/// <returns>The renderer texture state.</returns>
		/// <exception cref="ArgumentNullException"><c>image</c> is
		/// null.</exception>
		ITextureState LoadTexture(WrappedImage image);

		/// <summary>
		/// Resizes the screen to the specified dimensions.
		/// </summary>
		/// <param name="dimensions">The dimensions to resize to.</param>
		void Resize(Vector2 dimensions);

		/// <summary>
		/// Unloads the specified font.
		/// </summary>
		/// <param name="font">The font to unload.</param>
		/// <exception cref="ArgumentNullException"><c>font</c> is
		/// null.</exception>
		/// <exception cref="ArgumentException">Incompatible font
		/// state.</exception>
		void UnloadFont(IFontState font);

		/// <summary>
		/// Unloads the specified texture.
		/// </summary>
		/// <param name="texture">The texture to unload.</param>
		/// <exception cref="ArgumentNullException"><c>texture</c> is
		/// null.</exception>
		/// <exception cref="ArgumentException">Incompatible texture
		/// state.</exception>
		void UnloadTexture(ITextureState texture);

		/// <summary>
		/// Zooms in to the specified rect, converting to the specified
		/// scale.
		/// </summary>
		/// <param name="source">The source rect to zoom into.</param>
		/// <param name="scale">The new rect to render to.</param>
		/// <returns>A object that reverses the zoom on disposal.
		/// </returns>
		/// <remarks>Call this within a using statement.</remarks>
		IDisposable Zoom(Rect source, Rect scale);
	}
}